package com.boot.ys.mybatisplus.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.boot.ys.mybatisplus.entity.Role;
import com.boot.ys.mybatisplus.mapper.RoleMapper;
import com.boot.ys.mybatisplus.service.RoleService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 角色表 服务实现类
 * </p>
 *
 * @author Code Duck
 * @since 2021-10-21
 */
@Service
public class RoleServiceImpl extends ServiceImpl<RoleMapper, Role> implements RoleService {

    @Autowired
    private RoleMapper roleMapper;

    @Override
    public List<Role> gettest() {
        List<Role> roles = roleMapper.selectList(null);
        return roles;
    }


    @Override
    public IPage getPage() {
        long page1 = 1;
        long pageNum = 3;
        Page rolePage = new Page(page1, pageNum);
        Page page = roleMapper.selectPage(rolePage, null);
        return page;
    }

    @Override
    public List<Role> getWrapper(Role role) {
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("role_description",role.getRoleDescription());
        queryWrapper.like("role_description","测试");
        List<Role> list = roleMapper.selectList(queryWrapper);
        return list;
    }


    @Override
    public void update(Role role) {
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("id",role.getId());
        roleMapper.update(role,queryWrapper);

    }

    @Override
    public void deleteById(Role role) {
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("id",role.getId());
        roleMapper.delete(queryWrapper);
    }


}
